package com.yicun.HttpUtils;

import android.util.Log;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yicun.gloable.API;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;


import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/* loaded from: classes.dex */
public class OkHttpUtil {
    public static final int CONN_TIMEOUT = 10;
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private static final String TAG = "OkHttpUtil";
    public static final int TIMEOUT = 20;
    private static OkHttpUtil instance;
    OkHttpClient build;
    OkHttpClient build1;
    private Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
    OkHttpClient okHttpClient = new OkHttpClient();

    public interface OnCallback {
        void callback(String str);

        void onFailure(String str);
    }

    private OkHttpUtil() {
    }

    public static OkHttpUtil getInstance() {
        if (instance == null) {
            instance = new OkHttpUtil();
        }
        return instance;
    }

    private void init() {
        this.build1 = this.okHttpClient.newBuilder().connectTimeout(10L, TimeUnit.SECONDS).writeTimeout(20L, TimeUnit.SECONDS).readTimeout(20L, TimeUnit.SECONDS).build();
    }







    public void postAsynPostJson(String str, Map<String, Object> map, final OnCallback onCallback) {
        init();

        if (map == null) {
            onCallback.onFailure("请求参数不能为空");
            return;
        }
        if (API.BaseURL == null || API.BaseURL.length() <= 0) {
            return;
        }

        this.build1.newCall(new Request.Builder().url(API.BaseURL + str).post(RequestBody.create(JSON, this.gson.toJson(map))).build()).enqueue(new Callback() { // from class: com.example.MoJuGuiDingZhi.HttpUtils.OkHttpUtil.3
            @Override // okhttp3.Callback
            public void onFailure(Call call, IOException iOException) {
                onCallback.onFailure(iOException.getMessage());
            }

            @Override // okhttp3.Callback
            public void onResponse(Call call, Response response) throws IOException {
                onCallback.callback(response.body().string());
            }

        });
    }










}